<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/file-upload.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/form/FileUploadField.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript">
            var acMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.accesscontrol');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
            
            var idValue = getPrarmeterValue(window.location, 'id');
            var startPage = getPrarmeterValue(window.location, 'startPage');
            
            var ctGenderXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtGender');
            
            var ctGenderStore = new Ext.data.Store({
                reader: new Ext.data.XmlReader({
                    record: 'item',
                    id: 'code',
                    totalRecords: 'itemTotal'
                }, ['code', 'description']),
                data: ctGenderXmlLoader.getXml()
            });
            
            var ctGenderCombo = new Ext.form.ComboBox({
                fieldLabel: acMessage.get('ui.accesscontrol.ctgender'),
                id: 'ctGender',
                name: 'ctGender',
                editable: false,
                store: ctGenderStore,
                valueField: 'code',
                displayField: 'description',
                triggerAction: 'all',
                emptyText: message.get('message.combo.pleaseselect'),
                selectOnFocus: true,
                allowBlank: false,
                blankText: message.get('message.edit.noblank'),
                mode: 'local'
            });
            
            Ext.apply(Ext.form.VTypes, {
				userName: function(val, field){
					var isUserNameExistXmlLoader = new xmlLoader('../../servlet/AcUserServlet?action=100&userName=' + val + '&id=' + document.getElementById('id').value);
					var isExist = isUserNameExistXmlLoader.getValueByTagName('item');
					if(isExist == 'true'){
						return false;
					}
					return true;
				},
				userNameText: acMessage.get('ui.accesscontrol.usernameexist'),
				
                password: function(val, field){
                    if (field.initialPassField) {
                        var pwd = Ext.getCmp(field.initialPassField);
                        return (val == pwd.getValue());
                    }
                    return true;
                },
                
                passwordText: acMessage.get('ui.accesscontrol.donotmatch')
            });
            
            Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
                
                var acUserForm = new Ext.FormPanel({
					fileUpload: true,
                    labelAlign: 'left',
                    url: '../../servlet/AcUserServlet?action=1',
                    frame: true,
                    title: acMessage.get('ui.accesscontrol.changepwd'),
                    bodyStyle: 'padding:5px 5px 5px 5px;margin-top: 2px;',
                    width: '100%',
                    labelWidth: 120,
                    reader: new Ext.data.XmlReader({
                        record: 'item'
                    }, [{
                        name: 'id',
                        mapping: 'id'
                    }, {
                        name: 'userName',
                        mapping: 'userName'
                    }, {
                        name: 'realName',
                        mapping: 'realName'
                    }, {
                        name: 'userPwd',
                        mapping: 'userPwd'
                    }, {
                        name: 'comfirm',
                        mapping: 'userPwd'
                    }, {
                        name: 'macAddress',
                        mapping: 'macAddress'
                    }, {
                        name: 'department',
                        mapping: 'department'
                    }, {
                        name: 'duty',
                        mapping: 'duty'
                    }, {
                        name: 'mobile',
                        mapping: 'mobile'
                    }, {
                        name: 'tel',
                        mapping: 'tel'
                    }, {
                        name: 'email',
                        mapping: 'email'
                    }, {
                        name: 'photoName',
                        mapping: 'photoName'
                    }, {
                        name: 'ctGender',
                        mapping: 'ctGender'
                    }, {
                        name: 'comment',
                        mapping: 'comment'
                    }]),
                    items: [{
                        id: 'id',
                        name: 'id',
                        xtype: 'hidden'
                    },{
                        id: 'photoName',
                        name: 'photoName',
                        xtype: 'hidden'
                    }, {
                        layout: 'column',
                        items: [{
                            columnWidth: .33,
                            layout: 'form',
                            items: [{
                                xtype: 'textfield',
								vtype: 'userName',
                                fieldLabel: acMessage.get('ui.accesscontrol.username'),
                                name: 'userName',
                                anchor: '86%',
                                maxLength: 128,
								allowBlank: false,
                                blankText: message.get('message.edit.noblank'),
                                tabIndex: 1
                            }]
                        },{
                            columnWidth: .33,
                            layout: 'form',
                            items: [{
                                xtype: 'textfield',
                                fieldLabel: acMessage.get('ui.accesscontrol.realname'),
                                name: 'realName',
                                anchor: '86%',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank'),
                                maxLength: 128,
                                tabIndex: 1,
								readOnly: true
                            }]
                        }, {
                            columnWidth: .33,
                            layout: 'form',
                            items: [ctGenderCombo]
                        }]
                    }, {
                        layout: 'column',
                        items: [{
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
                                xtype: 'textfield',
                                inputType: 'password',
                                fieldLabel: '<img ext:qtip="' + acMessage.get('ui.accesscontrol.defaultpwd') + '&nbsp;&nbsp;:&nbsp;&nbsp; <font color=red>a1b2c3d4!</font>" src="../../images/icons/information.png" style="float: left;">&nbsp;&nbsp;&nbsp;&nbsp;' + acMessage.get('ui.accesscontrol.password'),
                                id: 'password',
                                name: 'userPwd',
                                anchor: '86%',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank'),
                                maxLength: 128,
                                tabIndex: 1,
								value: 'a1b2c3d4!'
                            }]
                        }, {
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
                                xtype: 'textfield',
                                inputType: 'password',
                                fieldLabel: acMessage.get('ui.accesscontrol.confirm'),
                                id: 'comfirm',
                                name: 'comfirm',
                                anchor: '86%',
                                allowBlank: false,
                                vtype: 'password',
                                initialPassField: 'password',
                                blankText: message.get('message.edit.noblank'),
                                maxLength: 128,
                                tabIndex: 1,
								value: 'a1b2c3d4!'
                            }]
                        }]
                    }, {
                        layout: 'column',
                        items: [{
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
                                xtype: 'textfield',
                                fieldLabel: acMessage.get('ui.accesscontrol.mac'),
                                name: 'macAddress',
                                anchor: '86%',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank'),
                                maxLength: 256,
                                tabIndex: 1,
								readOnly: true
                            }]
                        }, {
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
                                xtype: 'textfield',
                                fieldLabel: acMessage.get('ui.accesscontrol.department'),
                                name: 'department',
                                anchor: '86%',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank'),
                                maxLength: 256,
                                tabIndex: 1
                            }]
                        }]
                    },{
                        fieldLabel: acMessage.get('ui.accesscontrol.duty'),
                        name: 'duty',
                        xtype: 'textarea',
                        maxLength: 512,
                        width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
                    }, {
                        layout: 'column',
                        items: [{
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
                                xtype: 'textfield',
                                fieldLabel: acMessage.get('ui.accesscontrol.mobile'),
                                name: 'mobile',
                                anchor: '86%',
                                maxLength: 128,
                                tabIndex: 1
                            }]
                        }, {
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
                                xtype: 'textfield',
                                fieldLabel: acMessage.get('ui.accesscontrol.tel'),
                                name: 'tel',
                                anchor: '86%',
                                maxLength: 256,
                                tabIndex: 1
                            }]
                        }]
                    },{
                        layout: 'column',
                        items: [{
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
                                xtype: 'textfield',
								vtype: 'email',
                                fieldLabel: acMessage.get('ui.accesscontrol.email'),
                                name: 'email',
                                anchor: '86%',
                                maxLength: 128,
                                tabIndex: 1
                            }]
                        }, {
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
								xtype: 'fileuploadfield',
								width: '80%',
					            id: 'photo',
					            emptyText: message.get('message.edit.selectimage'),
					            fieldLabel: message.get('message.edit.photo'),
					            name: 'photo',
					            buttonCfg: {
					                text: '',
					                iconCls: 'uploadIcon'
				            	}
							}]
                        }]
                    },{
                        fieldLabel: message.get('message.edit.comment'),
                        name: 'comment',
                        xtype: 'textarea',
                        maxLength: 512,
                        width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
                    }],
                    
                    buttons: [{
                        text: message.get('message.edit.save'),
                        handler: function(){
                            if (acUserForm.getForm().isValid()) {
                            
                                document.getElementsByName('ctGender')[0].value = ctGenderCombo.getValue();
                                
                                acUserForm.getForm().submit({
                                    method: 'post',
                                    success: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                    },
                                    failure: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                    }
                                });
                            }
                        }
                    }]
                });
                
                acUserForm.render('acUserForm');
				
				new Ext.Resizable('customImg', {
		            wrap:true,
		            pinned:true,
					dynamic:true,
				    handles: 'all',
				    draggable:true
				});
				
                if (idValue != null) {
					document.getElementById('id').value = idValue;
					acUserForm.getForm().load({
							url:'../../servlet/AcUserServlet?action=3&id=' + idValue, 
							waitMsg:Ext.LoadMask.prototype.msg, 
							success: function(form, action){
								document.getElementById('customImg').src =  '../../_temp/' + document.getElementById('photoName').value;
							}
					});
				}
                
            });
        </script>
    </head>
    <body>
        <div id="acUserForm">
        </div>
		<img id="customImg" src="../../_temp/noimage.gif" style="position:absolute;left: 40%;width: 250px;"/>
    </body>
</html>
